package com.example.myproject;

import java.io.IOException;
import java.io.StringReader;
import java.util.Arrays;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.Menu;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MainActivity extends Activity {
	String responsestring;DocumentBuilder db;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

		StrictMode.setThreadPolicy(policy); 
		String url="http://www.roseindia.net/xml/sax/Employee-Detail.xml";
	

			//My Project 
			
			
			HttpParams params=new BasicHttpParams();
			HttpClient httpclient=new DefaultHttpClient(params);
			HttpGet httpGet=new HttpGet(url);
			try {
				HttpResponse response=httpclient.execute(httpGet);
				responsestring=EntityUtils.toString(response.getEntity());
				System.out.println(responsestring);
			} catch (ClientProtocolException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
			Document doc = null;
	        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	        
	            try {
					db = dbf.newDocumentBuilder();
				} catch (ParserConfigurationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	 
	            InputSource is = new InputSource();
	                is.setCharacterStream(new StringReader(responsestring));
	                try {
						doc = db.parse(is);
					} catch (SAXException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			
	                
	           NodeList nl=doc.getElementsByTagName("Employee");
	           for(int i=0;i<nl.getLength();i++){
	        	   Node n=nl.item(i);
	        	   
	        	   Element e=(Element)n;
	        	   
	        	   String name=e.getElementsByTagName("Emp_Name").item(0).getTextContent();
	        	   System.out.println(name);
	        	   
	           }
	                
	                
	                
	}

}
